package com.nokia.position;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.util.GenericOptionsParser;

public class DeleteEmptyLZO {

	public void printUsage() {
		System.out.println("Usage: hadoop jar path/to/this.jar "
				+ this.getClass() + " <path> <size>");

	}

	public int run(String[] args, Configuration conf) throws Exception {

		if (args.length != 2) {
			printUsage();
			return 1;
		}
		FileSystem fs = FileSystem.get(conf);

		FileStatus[] status = fs.listStatus(new Path(args[0]));
		for (int i = 0; i < status.length; i++) {
			FileStatus s = status[i];

			if (s.getLen() == Long.parseLong(args[1]) & !s.isDir()) {
				// Delete file
				fs.delete(s.getPath(), false);
			}
		}
		return (0);
	}

	public static void main(String[] args) throws Exception {
		Configuration conf = new Configuration();
		args = new GenericOptionsParser(conf, args).getRemainingArgs();
		DeleteEmptyLZO driver = new DeleteEmptyLZO();
		System.exit(driver.run(args, conf));
	}

}
